package hermesV2.services.P2P_Service;

import java.util.Date;
import java.util.Vector;

import hermesV2.PlaceAddress;
import hermesV2.agent.AbstractProtocol;
import hermesV2.agent.Interaction;


public class P2P_ServiceProtocol extends AbstractProtocol {
   /**
	 * 
	 */
	private static final long serialVersionUID = 5338161764057772696L;

public static final String REQUEST = "REQUEST";

   public static final String RESPONSE = "RESPONSE";

   public static final String ERROR = "ERROR";

   public static final String INVOKE = "INVOKE";

   public static final String INTERACTION1REQUEST = "AddIP";
   public static final String INTERACTION1RESPONSE = "ResponseAddIP";
   public static final String INTERACTION1ERROR = "ErrorAddIP";

   public static final String INTERACTION1REQUEST2  = "RequestSendEmailWithAttachment";
   public static final String INTERACTION1RESPONSE2 = "ResponseSendEmailWithAttachment";
   public static final String INTERACTION1ERROR2    = "ErrorSendEmailWithAttachment";
   
   public static final String INTERACTION2REQUEST = "AskPeersList";
   public static final String INTERACTION2RESPONSE = "ResponseAskPeersList";
   public static final String INTERACTION2ERROR = "ErrorAskPeersList";
   
   public static final String INTERACTION3REQUEST = "CreatePeersList";
   public static final String INTERACTION3RESPONSE = "ResponseCreatePeersList";
   public static final String INTERACTION3ERROR = "ErrorCreatePeersList";
   
   public static final String INTERACTION4REQUEST = "RemoveIP";
   public static final String INTERACTION4RESPONSE = "ResponseRemoveIP";
   public static final String INTERACTION4ERROR = "ErrorRemoveIP";
   
   public static final String INTERACTION5REQUEST = "UpdateList";
   public static final String INTERACTION5RESPONSE = "ResponseUpdateList";
   public static final String INTERACTION5ERROR = "ErrorUpdateList";
   
   public P2P_ServiceProtocol() {
       super("HubServiceProtocol");

       
       
       // #####  ADD IP  ####
       String[] parameterNameInteraction1Request = new String[3];
       parameterNameInteraction1Request[0] = "PeerPlace";
       parameterNameInteraction1Request[1] = "IsOnline";
       parameterNameInteraction1Request[2] = "CreationTime";
       
       Class<?>[] parameterTypeInteraction1Request = new Class[3];
       parameterTypeInteraction1Request[0] = PlaceAddress.class;
       parameterTypeInteraction1Request[1] = String.class;
       parameterTypeInteraction1Request[2] = Date.class;

       Interaction addIP = new Interaction(INTERACTION1REQUEST,
               "AddIP", REQUEST,
               parameterNameInteraction1Request,
               parameterTypeInteraction1Request);
       addInteraction(addIP);


       String[] parameterNameInteraction1Response = new String[2];
       parameterNameInteraction1Response[0] = "Response";
       parameterNameInteraction1Response[1] = "ReceiverBirthTime";
       Class<?>[] parameterTypeInteraction1Response = new Class[2];
       parameterTypeInteraction1Response[0] = String.class;
       parameterTypeInteraction1Response[1] = Date.class;
       Interaction responseAddIP = new Interaction(INTERACTION1RESPONSE,
               "ResponseAddIP",RESPONSE,
               parameterNameInteraction1Response,
               parameterTypeInteraction1Response);
       addInteraction(responseAddIP);
       addResponseLink(addIP,responseAddIP);

       //Error Dynamic Call Protocol Parameter
       String[] parameterNameInteraction1Error = new String[1];
       parameterNameInteraction1Error[0] = "Error";
       Class<?>[] parameterTypeInteraction1Error = new Class[1];
       parameterTypeInteraction1Error[0] = String.class;

       Interaction errorAddIP = new Interaction(INTERACTION1ERROR,"ErrorAddIP",ERROR,parameterNameInteraction1Error,parameterTypeInteraction1Error);

       addInteraction(errorAddIP);
       addErrorLink(addIP,errorAddIP);
       
       
       
       
       // #####  ASK PEER LIST  ####
     { 
       String[] parameterNameInteraction2Request = new String[1];
       parameterNameInteraction2Request[0] = "Null";
       
       Class<?>[] parameterTypeInteraction2Request = new Class[1];
       parameterTypeInteraction2Request[0] = String.class;
       Interaction asklist = new Interaction(INTERACTION2REQUEST,
               "AskPeersList", REQUEST,
               parameterNameInteraction2Request,
               parameterTypeInteraction2Request);
       addInteraction(asklist);


       String[] parameterNameInteraction2Response = new String[3];
       parameterNameInteraction2Response[0] = "PeersList";
       parameterNameInteraction2Response[1] = "AreOnline";
       parameterNameInteraction2Response[2] = "EventTime";
       Class<?>[] parameterTypeInteraction2Response = new Class[3];
       parameterTypeInteraction2Response[0] = Vector.class;
       parameterTypeInteraction2Response[1] = Vector.class;
       parameterTypeInteraction2Response[2] = Vector.class;
       Interaction responseAskList = new Interaction(INTERACTION2RESPONSE,
               "ResponseAskPeersList",RESPONSE,
               parameterNameInteraction2Response,
               parameterTypeInteraction2Response);
       addInteraction(responseAskList);
       addResponseLink(asklist,responseAskList);

       //Error Dynamic Call Protocol Parameter
       String[] parameterNameInteraction2Error = new String[1];
       parameterNameInteraction1Error[0] = "Error";
       Class<?>[] parameterTypeInteraction2Error = new Class[1];
       parameterTypeInteraction1Error[0] = String.class;

       Interaction errorAskList = new Interaction(INTERACTION2ERROR,"ErrorAskPeersList",ERROR,parameterNameInteraction2Error,parameterTypeInteraction2Error);

       addInteraction(errorAskList);
       addErrorLink(asklist,errorAskList);
     }
     
     
     // ##### CREATE LIST  #####
     { 
         String[] parameterNameInteraction3Request = new String[4];
         parameterNameInteraction3Request[0] = "PeersList";
         parameterNameInteraction3Request[1] = "AreOnline";
         parameterNameInteraction3Request[2] = "EventTime";
         parameterNameInteraction3Request[3] = "IDrequest";
         
         Class<?>[] parameterTypeInteraction3Request = new Class[4];
         parameterTypeInteraction3Request[0] = Vector.class;
         parameterTypeInteraction3Request[1] = Vector.class;
         parameterTypeInteraction3Request[2] = Vector.class;
         parameterTypeInteraction3Request[3] = String.class;
         Interaction createList = new Interaction(INTERACTION3REQUEST,
                 "CreatePeersList", REQUEST,
                 parameterNameInteraction3Request,
                 parameterTypeInteraction3Request);
         addInteraction(createList);


         String[] parameterNameInteraction3Response = new String[1];
         parameterNameInteraction3Response[0] = "Response";
         Class<?>[] parameterTypeInteraction3Response = new Class[1];
         parameterTypeInteraction3Response[0] = String.class;
         Interaction responseCreateList = new Interaction(INTERACTION3RESPONSE,
                 "ResponseCreatePeersList",RESPONSE,
                 parameterNameInteraction3Response,
                 parameterTypeInteraction3Response);
         addInteraction(responseCreateList);
         addResponseLink(createList,responseCreateList);

         //Error Dynamic Call Protocol Parameter
         String[] parameterNameInteraction3Error = new String[1];
         parameterNameInteraction3Error[0] = "Error";
         Class<?>[] parameterTypeInteraction3Error = new Class[1];
         parameterTypeInteraction3Error[0] = String.class;

         Interaction errorCreateList = new Interaction(INTERACTION3ERROR,"ErrorCreatePeersList",ERROR,parameterNameInteraction3Error,parameterTypeInteraction3Error);

         addInteraction(errorCreateList);
         addErrorLink(createList, errorCreateList);
       }
     
  // ##### REMOVE IP  #####
     { 
         String[] parameterNameInteraction4Request = new String[2];
         parameterNameInteraction4Request[0] = "PeerPlace";
         parameterNameInteraction4Request[1] = "DeathTime";
         
         Class<?>[] parameterTypeInteraction4Request = new Class[2];
         parameterTypeInteraction4Request[0] = PlaceAddress.class;
         parameterTypeInteraction4Request[1] = Date.class;
         Interaction removeIP = new Interaction(INTERACTION4REQUEST,
                 "RemoveIP", REQUEST,
                 parameterNameInteraction4Request,
                 parameterTypeInteraction4Request);
         addInteraction(removeIP);


         String[] parameterNameInteraction4Response = new String[1];
         parameterNameInteraction4Response[0] = "Response";
         Class<?>[] parameterTypeInteraction4Response = new Class[1];
         parameterTypeInteraction4Response[0] = String.class;
         Interaction responseremoveIP = new Interaction(INTERACTION4RESPONSE,
                 "ResponseRemoveIP",RESPONSE,
                 parameterNameInteraction4Response,
                 parameterTypeInteraction4Response);
         addInteraction(responseremoveIP);
         addResponseLink(removeIP,responseremoveIP);

         //Error Dynamic Call Protocol Parameter
         String[] parameterNameInteraction4Error = new String[1];
         parameterNameInteraction4Error[0] = "Error";
         Class<?>[] parameterTypeInteraction4Error = new Class[1];
         parameterTypeInteraction4Error[0] = String.class;

         Interaction errorremoveIP = new Interaction(INTERACTION4ERROR,"ErrorRemoveIP",ERROR,parameterNameInteraction4Error,parameterTypeInteraction4Error);

         addInteraction(errorremoveIP);
         addErrorLink(removeIP, errorremoveIP);
       }
     
     // ##### UPDATE LIST  #####     
     {
     String[] parameterNameInteraction5Request = new String[3];
     parameterNameInteraction5Request[0] = "PeersList";
     parameterNameInteraction5Request[1] = "AreOnline";
     parameterNameInteraction5Request[2] = "EventTime";
     
     Class<?>[] parameterTypeInteraction5Request = new Class[3];
     parameterTypeInteraction5Request[0] = Vector.class;
     parameterTypeInteraction5Request[1] = Vector.class;
     parameterTypeInteraction5Request[2] = Vector.class;
     Interaction updateList = new Interaction(INTERACTION5REQUEST,
             "UpdateList", REQUEST,
             parameterNameInteraction5Request,
             parameterTypeInteraction5Request);
     addInteraction(updateList);


     String[] parameterNameInteraction5Response = new String[1];
     parameterNameInteraction5Response[0] = "Response";
     Class<?>[] parameterTypeInteraction5Response = new Class[1];
     parameterTypeInteraction5Response[0] = String.class;
     Interaction responseUpdateList = new Interaction(INTERACTION5RESPONSE,
             "ResponseUpdateList",RESPONSE,
             parameterNameInteraction5Response,
             parameterTypeInteraction5Response);
     addInteraction(responseUpdateList);
     addResponseLink(updateList,responseUpdateList);

     //Error Dynamic Call Protocol Parameter
     String[] parameterNameInteraction5Error = new String[1];
     parameterNameInteraction5Error[0] = "Error";
     Class<?>[] parameterTypeInteraction5Error = new Class[1];
     parameterTypeInteraction5Error[0] = String.class;

     Interaction errorUpdateList = new Interaction(INTERACTION5ERROR,"ErrorUpdateList",ERROR,parameterNameInteraction5Error,parameterTypeInteraction5Error);

     addInteraction(errorUpdateList);
     addErrorLink(updateList, errorUpdateList);
   }   
     
   }
}